﻿using System;

namespace PropertyExpression.ControllableQuery.Test.Queries
{
    public partial class PartLinkQuery : IQuery<IPartLinkInfo>
    {
        private readonly IInnerPartLinkSwitcher innerPartLinkSwitcher;
        private readonly IParams<Params> @params;

        public PartLinkQuery(
            IInnerPartLinkSwitcher innerPartLinkSwitcher, IParams<Params> @params)
        {
            this.innerPartLinkSwitcher = innerPartLinkSwitcher;
            this.@params = @params;
        }

        public class Params
        {
            public readonly Guid BillOfMaterialsHeaderId;
            public readonly Guid ModelPublicationId;
            public readonly Guid ServicePartsPageId;

            public Params(
                Guid billOfMaterialsHeaderId,
                Guid modelPublicationId,
                Guid servicePartsPageId)
            {
                BillOfMaterialsHeaderId = billOfMaterialsHeaderId;
                ModelPublicationId = modelPublicationId;
                ServicePartsPageId = servicePartsPageId;
            }
        }
    }

    public interface IPartLinkInfo
    {
        string PartNumber { get; }
    }

    public interface IInnerPartLinkSwitcher
    {
        void AddSubQuery(Action<bool, IParams<WithInnerPartLinkSwitcher.Params>> action);
    }

    public class WithoutInnerPartLinkSwitcher : IInnerPartLinkSwitcher
    {
        public void AddSubQuery(Action<bool, IParams<WithInnerPartLinkSwitcher.Params>> action)
        {
            //no-op
        }
    }

    public class WithInnerPartLinkSwitcher : IInnerPartLinkSwitcher
    {
        private readonly bool latestPublicationOnly;
        private readonly IParams<Params> innerPartLinkParams;

        public WithInnerPartLinkSwitcher(
            bool latestPublicationOnly, IParams<Params> innerPartLinkParams)
        {
            this.latestPublicationOnly = latestPublicationOnly;
            this.innerPartLinkParams = innerPartLinkParams;
        }

        public void AddSubQuery(Action<bool, IParams<Params>> action)
        {
            action(latestPublicationOnly, innerPartLinkParams);
        }

        public class Params
        {
            public readonly string LanguageCode;
            public readonly Guid ModelId;

            public Params(string languageCode, Guid modelId)
            {
                LanguageCode = languageCode;
                ModelId = modelId;
            }
        }
    }
}
